package cn.jtfadmin.codegen.domain.dto;

import cn.jtfadmin.codegen.utils.CodeGenUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Objects;

@Getter
@Setter
public class ClassDTO implements Serializable {
    /**
     * 类命
     */
    protected String className;

    /**
     * 类简单名
     */
    protected String packageName;

    /**
     * 字段类名
     */
    protected String classSimpleName;

    public ClassDTO(String className) {
        if(!StringUtils.hasText(className)){
            throw new IllegalArgumentException("类名不能为空");
        }
        this.className = className;
        this.classSimpleName = CodeGenUtils.getClassSimpleName(className);
        this.packageName = CodeGenUtils.getPackageName(className);
    }

    public ClassDTO() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClassDTO that = (ClassDTO) o;
        return Objects.equals(className, that.className);
    }

    @Override
    public int hashCode() {
        return Objects.hash(className);
    }
}
